﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using bzxxxt.admin.service;
using bzxxxt.bll;
using bzxxxt.model;

namespace bzxxxt.admin.ashx
{
    /// <summary>
    /// a 的摘要说明
    /// </summary>
    public class init : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            InitBLL init = new InitBLL();
            context.Response.ContentType = "text/html";
            string action = context.Request.Params["init"];
            switch (action) {
                case "map":
                    {
                        init.InitMap();
                        context.Response.Write("OK!");
                        break;
                    }
                case "t":
                    {
                        context.Response.Write("init t start...");
                        context.Response.Flush();
                        context.Response.Write("init t end...");
                        break;
                    }
                case "area":
                    {
                        string url = "http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2015/32/05/320582.html";
                        List<AreaModel> townlist=init.getTownList(url);
                        
                        string msg = init.InitTownList(townlist);
                        context.Response.Write(msg + "<br/>");
                        foreach (var town in townlist)
                        { 
                            context.Response.Write(town.code + "__" + town.name+"<br/>");
                            foreach(var v in town.children){
                                context.Response.Write("__" + v.code + "__" + v.name + "<br/>");
                            }
                            context.Response.Flush();
                        }
                        break;
                    }
                case "test1":
                    {
                        context.Response.Write("init test1 start...");
                        context.Response.Flush();
                        init.testdata1();                       
                        context.Response.Write("init test1 ok!");
                        break;
                    }
                case "test2":
                    {
                        context.Response.Write("init test2 start...");
                        context.Response.Flush();
                        init.testdata2();
                        context.Response.Write("init test2 ok!");
                        break;
                    }
                case "test3":
                    {
                        context.Response.Write("init test start3...");
                        context.Response.Flush();
                        init.testdata3();
                        context.Response.Write("init test3 ok!");
                        break;

                    }
                case "all":
                    init.InitAll();
                    context.Response.Write("init all ok");
                    break;
                case "paradise":
                    init.InitParadiseUser();
                    context.Response.Write("init paradise ok");
                    break;
                case "relative":
                    init.InitRelative();
                    context.Response.Write("init relative ok");
                    break;
                case "dept":
                    init.InitDepartment();
                    context.Response.Write("init area ok");
                    break;
                case "grave":
                    init.InitGrave2();
                    context.Response.Write("init grave ok");
                    break;
                case "qrcode": {
                    string fileName = JsonUtil.CreateQrCode("http://192.168.88.107:8110/admin/ashx/init.ashx?init=qrcode&我是中国人", "aa");
                    context.Response.Write("<img src='"+fileName+"' />");
                    break;
                }

            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}